﻿using Mathmall.Administration.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Mathmall.Administration.Data
{
    public class AttrEntityTypeConfiguration : IEntityTypeConfiguration<Attr>
    {
        public void Configure(EntityTypeBuilder<Attr> builder)
        {
            // 不使用output子句
            builder.ToTable(table => table.UseSqlOutputClause(false));

            builder
                .ToTable(nameof(Attr))
                .ToTable(tableBuilder => tableBuilder.HasComment("商品属性"));

            builder
                .HasKey(attr => attr.AttrID)
                .HasName("AttrID");

            builder
                .Property(attr => attr.AttrName)
                .HasColumnName("AttrName")
                .HasColumnType("nvarchar(30)")
                .HasComment("属性名")
                .IsRequired();

            builder
                .Property(attr => attr.SearchType)
                .HasColumnName("SearchType")
                .HasColumnType("tinyint")
                .HasComment("是否需要检索[0-不需要，1-需要]")
                .IsRequired(false);

            builder
                .Property(attr => attr.Icon)
                .HasColumnName("Icon")
                .HasColumnType("varchar(255)")
                .HasComment("属性图标")
                .IsRequired(false);

            builder
                .Property(attr => attr.ValueSelect)
                .HasColumnName("ValueSelect")
                .HasColumnType("nvarchar(255)")
                .HasComment("可选值列表[用逗号分隔]")
                .IsRequired(false);

            builder
                .Property(attr => attr.AttrType)
                .HasColumnName("AttrType")
                .HasColumnType("tinyint")
                .HasComment("属性类型[0-销售属性，1-基本属性，2-既是销售属性又是基本属性]")
                .IsRequired(false);

            builder
                .Property(attr => attr.Enable)
                .HasColumnName("Enable")
                .HasColumnType("tinyint")
                .HasComment("可选值列表[用逗号分隔]")
                .IsRequired(false);

            builder
                .Property(attr => attr.CatalogID)
                .HasColumnName("CatalogID")
                .HasColumnType("int")
                .HasComment("所属分类")
                .IsRequired(true);

            builder
                .Property(attr => attr.ShowDescription)
                .HasColumnName("ShowDescription")
                .HasColumnType("tinyint")
                .HasComment("快速展示【是否展示在介绍上；0-否 1-是】，在sku中仍然可以调整")
                .IsRequired(false);

            builder
                .Property(attr => attr.CreateTime)
                .HasColumnName("CreateTime")
                .HasColumnType("datetime")
                .HasComment("创建时间")
                .IsRequired(false);

            builder
                .Property(attr => attr.LastUpdateTime)
                .HasColumnName("LastUpdateTime")
                .HasColumnType("datetime")
                .HasComment("最后更新时间")
                .IsRequired(false);
        }
    }
}